#region Copyright note and modification history

/*
-----------------------------------------------------------------------------
Copyright (c) 2006 HSI Inc. All Rights Reserved.

PROPRIETARY NOTICE: This software has been provided pursuant to a
License Agreement that contains restrictions on its use. This software
contains valuable trade secrets and proprietary information of
HSI Inc and is protected by Federal copyright law. It may not
be copied or distributed in any form or medium, disclosed to third parties,
or used in any manner that is not provided for in said License Agreement,
except with the prior written authorization of HSI Inc.

-----------------------------------------------------------------------------
$Log: /CoreServices/Hsi/Drawing/ResourceHelper.cs $
 * 
 * 2     9/01/06 9:23a Nathan_stults
-----------------------------------------------------------------------------
*/

#endregion

using System;
using System.Drawing;
using System.IO;
using System.Reflection;

namespace SimplePushpinGenerator
{
    /// <summary>
    /// Summary description for ResourceHelper.
    /// </summary>
    public class ResourceHelper
    {
        public static Bitmap LoadBitmap(Type assemblyType, string imageName)
        {
            Assembly myAssembly = Assembly.GetAssembly(assemblyType);
            return LoadBitmap(myAssembly, imageName);
        }

        public static Bitmap LoadBitmap(Assembly assembly, string imageName)
        {
            Stream imageStream = assembly.GetManifestResourceStream(imageName);

            // Load the bitmap from stream
            try
            {
                using (var image = new Bitmap(imageStream))
                {
                    return new Bitmap(image, image.Width, image.Height);
                }
            }
            finally
            {
                imageStream.Close();
            }
        }

        public static Icon LoadIcon(Type assemblyType, string iconName)
        {
            // Get the assembly that contains the bitmap resource
            Assembly myAssembly = Assembly.GetAssembly(assemblyType);

            // Get the resource stream containing the images
            Stream iconStream = myAssembly.GetManifestResourceStream(iconName);

            // Load the Icon from the stream
            return new Icon(iconStream);
        }

        public static Icon LoadIcon(Type assemblyType, string iconName, int width, int height)
        {
            // Get the assembly that contains the bitmap resource
            Assembly myAssembly = Assembly.GetAssembly(assemblyType);

            // Get the resource stream containing the images
            Stream iconStream = myAssembly.GetManifestResourceStream(iconName);

            // Load the Icon from the stream
            return new Icon(iconStream, width, height);
        }
    }
}